#!/usr/bin/perl -w
use strict;
use FindBin;
use lib ("$FindBin::Bin/..", "/net/cpp-group/Leo/bin");
use cluster_from_pairs;
use parse_bl2seq;
use DBI;
use DBD::Pg;
use linewrap;


(my $my_dir = $FindBin::Bin) =~ s/(.*)\/$/$1/;

print STDERR <<"HEADLINE";
888888888888888888888888888888888888888888888888888888888888888888888

    table_genome_genome_align

	Description:

888888888888888888888888888888888888888888888888888888888888888888888

HEADLINE

#-----------------------------------------------------------------------------------------
#	Get DB parameters
#
use db_parameters;
use ortho_species;
#
#	Get DB parameters
#-----------------------------------------------------------------------------------------



print STDERR "\trun make\n";

my $dbh = connect_to_panda();
use get_psql_time;
my $start_time = get_psql_time($dbh);

# change to makefile directory
use Cwd qw(abs_path getcwd); # 'abs_path';
my $curr_dir = getcwd();
print STDERR $my_dir, "\n";
chdir($my_dir);


my $species_pair = $ortho_name1.'_'.$ortho_name2;

my $dir_base = abs_path("$my_dir/..");
my $dir_ds_pipeline = "$dir_pipeline_ds_temp/$species_pair";
print STDERR ("gmake -f makefile.mak -j 100 -n ".
		"PROJ_NAME=$species_pair ".
		"SPECIES1=$ortho_name1 ".
		"SPECIES2=$ortho_name2 ".
		"REGEX1=$ortho_prot1 ".
		"REGEX2=$ortho_prot2 ".
		"DIR_PROJECT=$dir_base ".
		"DIR_PIPELINE_TMP=$dir_ds_pipeline ".
		"DIR_OUTPUT=$dir_orthologs_output ".
		"do_fifth_part\n");
system("gmake -f makefile.mak -j 100 ".
		"PROJ_NAME=$species_pair ".
		"SPECIES1=$ortho_name1 ".
		"SPECIES2=$ortho_name2 ".
	    "REGEX1=$ortho_prot1 ".
	    "REGEX2=$ortho_prot2 ".
		"DIR_PROJECT=$dir_base ".
		"DIR_PIPELINE_TMP=$dir_ds_pipeline ".
		"DIR_OUTPUT=$dir_orthologs_output ".
		"do_fifth_part\n") and die;


# restore directory
chdir ($curr_dir);
log_pipeline_stage($dbh, 'NULL', 30, 'genome_genome_align/ds', $start_time);

$dbh->disconnect;
